<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Tool_TruncateDBAction
 *
 * @author Alen
 */
class Tool_TruncateDBAction extends AdmincpAction {
    //put your code here
    public function index(){
        
        $group=  request_string('group');
        
        // 设置页面导航
        $this->set_breadcrumb(array('工具箱'=>'###','重置数据'=>'?m=Tool_TruncateDB'));
        
        // 设置页面标题
        $this->set_h1('');
        
        // 设置页面信息,如页面标题,meta信息等
        $this->set_page_info('重置数据');
        
        if(!$this->dm) $this->dm=new SoDataModule();
        
        if($group){
            switch(strtolower($group)){
                case 'finance':
                    foreach(array('tfinanceaccount','tfinancerecharge','tfinancetransaction','tfinancetransactionlog','tfinancewithdrawal') as $tbl){
                        $this->dm->execute_sql('truncate table '.$tbl);
                    }
                    break;
            }
            $this->assign('table', '数据已清空!');
            $this->display();
            return;
        }
        $set=$this->dm->show_tables();
        $str='<input type="checkbox" id="chkAll" />全部<form method="post" action="#"><input type="submit" value="Truncate" /><ul>';
        foreach($set as $item){
            $str.='<li><input type="checkbox" name="tbls[]" value="'.$item.'" />'.$item.'</li>';
        }
        $str.='</ul><input type="hidden" name="action" value="save" /></form>';
        $this->assign('table', $str);
        $this->display();
    }
    public function save(){
        $tbls=  request_string('tbls');
        if(!$tbls) redirect('没有选择任何表!');
        if(!$this->dm) $this->dm=new SoDataModule();
        foreach($tbls as $tbl){
            $this->dm->execute_sql('truncate table '.$tbl);
        }
        redirect('已清空');
    }
}
